package com.oscarmovie.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.oscarmovie.model.Description;
import com.oscarmovie.model.DescriptionPerson;

public class DescriptionDaoImpl extends HibernateDaoSupport implements DescriptionDao {

	public Description load(int id) {
		Description description = (Description)getSession().load(Description.class, id);
		return description;
	}
	
	public List<Description> list() {
		Query query = getSession().createQuery("from Description");
		query.setCacheable(true);
		List<Description> list = (List<Description>)query.list();
		return list;
	}
	public List<Description> listByMovieId(int movieId) {
		Query query = getSession().createQuery("from Description");
		query.setCacheable(true);
		List<Description> list = (List<Description>)query.list();
		return list;
	}
	
	public List<Description> listByAccountId(int accountId) {
		Query query = getSession().createQuery("from Description");
		query.setCacheable(true);
		List<Description> list = (List<Description>)query.list();
		return list;
	}
	
	public void save(Description description) {
		getSession().saveOrUpdate(description);
	}

	public Description loadByWeiboId(String weiboId) {
		Query query = getSession().createQuery("from Description description where description.weiboId = :weiboId");
		query.setString("weiboId", weiboId);
		Description description = (Description)query.uniqueResult();
		return description;
	}
	
}
